package com.ahu.Repository;

import com.ahu.domain.RepairLog;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;
import com.ahu.domain.ReapirInfoDetailModel;
import javax.persistence.EntityManager;
import com.ahu.domain.RepairCur;
import javax.persistence.PersistenceContext;
import java.util.*;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;


/**
 * Created by qx on 2018/3/22.
 */
@Repository
public class RepairInfoRepository {
    @PersistenceContext
    private EntityManager entityManager;

    public List<ReapirInfoDetailModel> findByNumber(String number) {
        String datasql = "select id,repairOrderNumber,repairAddress,repairContext,repairDate,repairTime,submitTime,repairStatus,updateTime from RepairCur repairCur where repairCur.number = :number";
        String datasql1 = "select id,repairOrderNumber,repairAddress,repairContext,repairDate,repairTime,submitTime,repairStatus,updateTime from RepairLog repairLog where repairLog.number = :number";

        List<Object[]> list = entityManager.createQuery(datasql, Object[].class)
                .setParameter("number", number)
                .getResultList();

        List<Object[]> list1 = entityManager.createQuery(datasql1, Object[].class)
                .setParameter("number", number)
                .getResultList();

        List<ReapirInfoDetailModel> reapirInfoDetailModelList = new ArrayList<>();
        list.forEach(e-> reapirInfoDetailModelList.add(new ReapirInfoDetailModel(
                (Integer) e[0],
                (String) e[1],
                (String) e[2],
                (String) e[3],
                (String) e[4],
                (String) e[5],
                (Date) e[6],
                (String) e[7],
                (Date) e[8]
        )));
        list1.forEach(e-> reapirInfoDetailModelList.add(new ReapirInfoDetailModel(
                (Integer) e[0],
                (String) e[1],
                (String) e[2],
                (String) e[3],
                (String) e[4],
                (String) e[5],
                (Date) e[6],
                (String) e[7],
                (Date) e[8]
        )));
        return reapirInfoDetailModelList;

    }

}
